using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Dracham.GUI.Controls
{
    public class Button : Control
    {
        private Vector2 position;
        private Rectangle texturePart;
        private Texture2D texture;

        public Button(Vector2 position, Rectangle texturePart, Texture2D texture)
        {
            this.position = position;
            this.texturePart = texturePart;
            this.texture = texture;
        }

        #region events 

        public event EventHandler Click;
        private void OnClick()
        {
            if (this.Click != null)
            {
                this.Click(this, EventArgs.Empty);
            }
        }

        #endregion

        public override void Update(GameTime gameTime, MouseState mouseState, KeyboardState keyboardState)
        {
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                this.OnClick();
            }
        }

        public void Render(SpriteBatch spriteBatch, GameTime gameTime)
        {
            spriteBatch.Draw(texture, new Rectangle((Int32)position.X, (Int32)position.Y, texturePart.Width, texturePart.Height), texturePart, Color.White);
        }
    }
}
